package trees;

public class PlusTree {
    /**
     * 给二叉树的每个节点+1
     *
     * @param treeNode 二叉树
     */
    public void plusTree(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }

        treeNode.val += 1;
        plusTree(treeNode.left);
        plusTree(treeNode.right);
    }

    public static void main(String[] args) {
        TreeNode treeNode = TreeNode.buildTree(1);

        PlusTree plusTree = new PlusTree();
        treeNode.preTraverse(treeNode);
        plusTree.plusTree(treeNode);
        System.out.println();
        treeNode.preTraverse(treeNode);
    }
}
